<?php
require_once('./class/Frequence.php');

switch(@$_GET['action']){

    default:
        echo _FREQUENCE_;
    break;

    case "addForm":
        echo Frequence::getAddForm();
        break;

    case "doAdd":
        $f = new Frequence();
        $f->setNom($_POST['nom']);
        $f->addOrModify();
        echo $f->getNom()." "._ADDED_;
        break;

    case "modifyForm":
        $f = Frequence::getFrequence($_GET['id']);
        echo $f->getModifyForm();
        break;

    case "doModify":
        $f = new Frequence();
        $f->setId($_POST['id_frequence']);
        $f->setNom($_POST['nom']);
        $f->addOrModify();
        echo _FREQUENCE_.' '._MODIFIED_;
        break;

    case "list":
        $array = Frequence::getAllFrequence();
        $html = '<table class="tablesorter">
						<thead>
							<th>'._ID_FREQUENCE_.'</th>
							<th>'._NOM_FREQUENCE_.'</th>
							<th>'._EDIT_.'</th>
							<th>'._DELETE_.'</th>
						</thead><tbody>';
        $i = 0;
        foreach($array as $r){
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
						<td>'.$r->getId().'</td>
						<td> ' .$r->getNom().'</td>
						<td><a href="?module=frequence&action=modifyForm&id='.$r->getId().'">'._EDIT_.'</a></td>
						<td><a href="?module=frequence&action=delete&id='.$r->getId().'">'._DELETE_.'</a></td>
					</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;

    case "delete":
        $f = Frequence::getFrequence($_GET['id']);
        $f->delete();
        echo $f->getNom().' '._DELETED_;
        break;
}
?>
